package com.foolishbird.sdk.ui.assist;

import android.content.Context;
import android.os.CountDownTimer;
import android.widget.Button;

import com.foolishbird.sdk.utils.ResUtils;


public final class VerifyCodeCountDownTimer extends CountDownTimer {

    private static final long MILLIS_FUTURE = 60 * 1000L;
    private static final long COUNT_DOWN_INTERVAL = 1000L;
    private final Button countDownView;
    private final Context context;

    public VerifyCodeCountDownTimer(Button view) {
        super(MILLIS_FUTURE, COUNT_DOWN_INTERVAL);
        this.countDownView = view;
        context = countDownView.getContext();
    }

    @Override
    public void onTick(long millisUntilFinished) {
        if(countDownView.isClickable()){
            countDownView.setClickable(false);
            countDownView.setBackgroundResource(ResUtils.getDrawableIdentifier(context, "wan_selector_button_bg_code_gray"));
        }
        String text = context.getString(ResUtils.getStringIdentifier(context, "hnssn_hint_surplus"), millisUntilFinished / 1000);
        countDownView.setText(text);
    }

    @Override
    public void onFinish() {
        if(!countDownView.isClickable()){
            countDownView.setClickable(true);
            countDownView.setBackgroundResource(ResUtils.getDrawableIdentifier(context, "wan_shape_forget_bg"));
        }
        countDownView.setText(ResUtils.getStringIdentifier(context, "hnssn_get_captcha"));
    }
}
